{include file="public/_header" /}
<style>
    #mainForm {
        max-width: 700px;
        margin: 30px auto;
    }

    #mainForm .layui-form-item {
        margin-bottom: 25px;
    }
</style>
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-header">{$title}</div>
        <div class="layui-card-body">
            <form class="layui-form" id="mainForm">
                <div class="layui-form-item">
                    <label class="layui-form-label layui-form-required">用户名:</label>
                    <div class="layui-input-block">
                        <input name="userName" id="userName" value="{$data.user_name}" placeholder="请输入" required class="layui-input"
                               lay-verType="tips"/>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label layui-form-required">密码:</label>
                    <div class="layui-input-block">
                        <input type="password" name="password" id="password" required placeholder="请输入密码" class="layui-input"
                               lay-verType="tips"/>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label layui-form-required">姓名:</label>
                    <div class="layui-input-block">
                        <input type="text" name="name" id="name" value="{$data.name}" required placeholder="请输入姓名" class="layui-input"
                               lay-verType="tips"/>
                    </div>
                </div>

                <div class="form-group-bottom text-center">
                    <button type="reset" class="layui-btn layui-btn-primary">&emsp;重置&emsp;</button>
                    <button class="layui-btn" lay-filter="add" lay-submit>&emsp;提交&emsp;</button>
                </div>
                <input type="hidden" name="id" value="{$data.id}">
            </form>
        </div>
    </div>
</div>
{include file="public/_footer"}
<script>
    layui.use(['form', 'element'], function () {
        var form = layui.form;
        var $ = layui.jquery;
        form.on('submit(add)', function (data) {
            var arr = data.field;
            if($.trim(arr.userName) === '') {
                layer.msg('用户名不能为空!');
                return false;
            }

            if($.trim(arr.name) === '') {
                layer.msg('姓名不能为空!');
                return false;
            }

            // 提交数据
            $.post('{:url("persional")}', arr, function (res) {
                if(res.code === 0) {
                    layer.open({
                        type: 1
                        ,offset: 'auto'
                        ,id: 'layerDemo' //防止重复弹出
                        ,content: '<div style="padding: 20px 100px;">'+ res.msg +'</div>'
                        ,btn: '关闭'
                        ,btnAlign: 'c' //按钮居中
                        ,shade: 0 //不显示遮罩
                        ,yes: function(){
                            window.location.href = "{:url('persional')}";//'index.html';
                            layer.closeAll();
                        }
                    });
                }else {
                    layer.msg(res.msg);
                }
            },'JSON');
            return false;
        });




    });


</script>
</body>
</html>